package com.totobox.apps.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;

import com.totobox.apps.Const;
import com.totobox.apps.R;
import com.totobox.apps.common.MoveActivity;
import com.totobox.apps.common.NoticeCustomDialog;
import com.totobox.apps.common.TotoIFData;

public class MyTotoActivity extends BasicActivity {
	
	private int NOTICE_DIALOG = 3;
	private AlertDialog.Builder dialog = null;
	
	public Thread thread = null;
	
	private ImageButton btn_main_img;
	private ImageButton btn_main_vod;
	private ImageButton btn_main_aud;
	private ImageButton btn_main_etc;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.my_toto_main);
        
        //상단 타이틀 초기화
        //super.initTitle();
        
        btn_main_img = (ImageButton) findViewById(R.id.btn_main_img);
        btn_main_vod = (ImageButton) findViewById(R.id.btn_main_vod);
        btn_main_aud = (ImageButton) findViewById(R.id.btn_main_aud);
        btn_main_etc = (ImageButton) findViewById(R.id.btn_main_etc);
        
        btn_main_img.setOnClickListener(this);
        btn_main_vod.setOnClickListener(this);
        btn_main_aud.setOnClickListener(this);
        btn_main_etc.setOnClickListener(this);
        
        this.init();
        
        //최상위 폴더 데이터 추출
        thread = new Thread(null , mainFolder);
        thread.start();
    }

	@Override
	public void onClick(View v) {
		
		if(v == btn_main_img){
			Const.MENU = "IMG";
		}
		else if(v == btn_main_vod){
			Const.MENU = "VOD";
		}
		else if(v == btn_main_aud){
			Const.MENU = "AUD";
		}
		else if(v == btn_main_etc){
			Const.MENU = "ETC";
		}
		this.moveActivity(this);
	}
    
	public void moveActivity(Activity act){
		
		// TODO Auto-generated method stub
		MoveActivity go = null;
		
		//마이 토토 메인 페이지는 살린다.
		if(act instanceof MyTotoActivity){
			go = new MoveActivity(this, MyTotoFolderActivity.class);
			go.startActivity();
		}
		else if("VOD".equals(Const.MENU)){
			go = new MoveActivity(this, TotoVodPlayerActivity.class);
			go.startActivity();
		}
		else if("AUD".equals(Const.MENU)){
			go = new MoveActivity(this, TotoMusicPlayerActivity.class);
			go.startActivity();
		}
		else{
			go = new MoveActivity(this, MyTotoFolderActivity.class);	
			go.startActivity(this);
		}
	}
	
	public void init(){
		
		if(!Const.isAlertView)
			this.ShowAlertDialog(NOTICE_DIALOG);
    }
	
	public void ShowAlertDialog(int i){
    	
    	if(i == NOTICE_DIALOG){
			
    		Dialog dialog = new NoticeCustomDialog(this);
    		dialog.show();

		}
    }
	
	/**
	 * 
	 */
	private Runnable mainFolder = new Runnable() {
    	public void run() {
    		try {
    			
    			Const.mainFolder.putAll(TotoIFData.Folder());
    			
    		} catch (Exception e) {
    			Log.d("partData : ", e.toString());
    		}
    	}
    };
	    
}